﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ControlGetItems - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The ControlGetItems function returns an array of items/rows from a ListBox, ComboBox, or DropDownList." />
<meta name="ahk:equiv-v1" content="commands/ControlGet.htm#List" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>ControlGetItems</h1>

<p>Returns an array of items/rows from a ListBox, ComboBox, or DropDownList.</p>

<pre class="Syntax">Items := <span class="func">ControlGetItems</span>(Control <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span>)</pre>

<h2>Parameters</h2>
<dl>
    <dt>Control</dt>
    <dd>
        <p>Type: <a href="../Concepts.htm#strings">String</a>, <a href="../Concepts.htm#numbers">Integer</a> or <a href="../Objects.htm">Object</a></p>
        <p>The control's ClassNN, text or HWND, or an object with a <code>Hwnd</code> property. For details, see <a href="Control.htm#Parameter">The Control Parameter</a>.</p>
    </dd>
    <dt>WinTitle</dt>
    <dd>
        <p>Type: <a href="../Concepts.htm#strings">String</a>, <a href="../Concepts.htm#numbers">Integer</a> or <a href="../Objects.htm">Object</a></p>
        <p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
    </dd>
    <dt>WinText</dt>
    <dd>
        <p>Type: <a href="../Concepts.htm#strings">String</a></p>
        <p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p>
    </dd>
    <dt>ExcludeTitle</dt>
    <dd>
        <p>Type: <a href="../Concepts.htm#strings">String</a></p>
        <p>Windows whose titles include this value will not be considered.</p>
    </dd>
    <dt>ExcludeText</dt>
    <dd>
        <p>Type: <a href="../Concepts.htm#strings">String</a></p>
        <p>Windows whose text include this value will not be considered.</p>
    </dd>
</dl>

<h2>Return Value</h2>
<p>Type: <a href="../objects/Array.htm">Array</a></p>
<p>This function returns an array of items/rows.</p>

<h2>Error Handling</h2>
<p>An exception is thrown on failure. Failure occurs when: 1) the target window or control does not exist; 2) the target control is not of a recognized type; 3) a message could not be sent to the target control.</p>

<h2>Remarks</h2>
<p>Some applications store their item data privately, which prevents their text from being retrieved. In these cases, an exception will usually not be thrown, but all the retrieved fields will be empty.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h2>Related</h2>
<p><a href="ListViewGetContent.htm">ListViewGetContent</a>, <a href="WinGetList.htm">WinGetList</a>, <a href="Control.htm">Control functions</a></p>

<h2>Examples</h2>
<div class="ex" id="ExFor">
<p><a href="#ExFor">#1</a>: Accesses the items one by one.</p>
<pre>for item in ControlGetItems("ComboBox1", WinTitle)
    MsgBox "Item number " A_Index " is " item</pre>
</div>

<div class="ex" id="ExIndex">
<p><a href="#ExIndex">#2</a>: Accesses a specific item by index.</p>
<pre>items := ControlGetItems("ListBox1", WinTitle)
MsgBox "The first item is " items[1]
MsgBox "The last item is " items[-1]</pre>
</div>

</body>
</html>